<?php

namespace common\components;

use creocoder\nestedsets\NestedSetsQueryBehavior;

/**
 * 支持嵌套查询的ActiveQuery
 *
 * @method ActiveQuery roots()
 * @method ActiveQuery leaves()
 * @package common\components
 */
class ActiveQueryNS extends ActiveQuery
{

    /**
     * @var array 默认排序
     */
    protected $defaultSort = [
        'order_num' => SORT_DESC,
        'lft' => SORT_ASC,
    ];

    /**
     * {@inheritdoc}
     */
    public function behaviors()
    {
        return [
            NestedSetsQueryBehavior::className(),
        ];
    }

    /**
     * {@inheritdoc}
     */
    public function sort()
    {
        $this->orderBy($this->defaultSort);
        return $this;
    }
}
